#include <stdio.h>
#include <pthread.h>
#include <unistd.h>


void * start_routine(void * arg)
{
    printf("sub thread is running.\n");
    printf("sub thread id is %ld\n", pthread_self());

    sleep(5);//休眠5秒钟, 单位为秒

    return NULL;//返回的是空指针
}

int main()
{
    pthread_t pthid = 0;
    ///经过pthread_create函数之后，pthid的值会进行修改
    pthread_create(&pthid, NULL, start_routine, NULL);

    //打印pthid是在主线程中进行的
    printf("main: sub thread id is %ld\n", pthid);
    printf("main thread id is %ld\n", pthread_self());

    printf("main thread is joining\n");
    /* while(1); */
    //主线程等待子线程执行结束
    //pthread_join是一个阻塞式函数，直到子线程执行结束，才会返回
    pthread_join(pthid, NULL);
    printf("main thread is exiting\n");
    return 0;
}

